//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by 石林 on 15/11/8.
//  Copyright © 2015年 石林. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = MainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")

        //添加子视图控制器
        addChildViewControllers()
        
        mainTabBar.addComposeBtn.addTarget(self, action: "composeDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    @objc private func composeDidClick() {
        print(__FUNCTION__)
    }
    
    private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController( ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        
//        self.tabBar.tintColor = UIColor.orangeColor()
        
        vc.title = title
        
        //实例化导航视图控制器
        let nav = UINavigationController(rootViewController: vc)
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
//        vc.tabBarItem.selectedImage = UIImage(named: imageName +  "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(nav)
    }


}
